const crypto = require("crypto-js");

// function _0x3675(_0x219bb4) {
//   _0x219bb4 = _0x219bb4 - 0x0;
//   var _0xbf75cc = _0x31d2[_0x219bb4];
//   return _0xbf75cc;
// }

function _0xb7b00b(_0x478f45, _0x39d8b5, _0x3345a2) {
  var _0x285b84 = crypto["enc"]["Utf8"]["parse"](_0x3345a2),
    _0x361e3d = crypto["lib"]["CipherParams"]["create"]({
      ciphertext: crypto["enc"]["Hex"]["parse"](_0x39d8b5),
    }),
    _0x15ab36 = crypto["AES"]
      ["decrypt"](_0x361e3d, crypto["enc"]["Utf8"]["parse"](_0x478f45), {
        iv: _0x285b84,
      })
      ["toString"](crypto["enc"]["Utf8"]);
  return _0x15ab36;
}

function _0x3add6c(_0x478f45, _0x39d8b5, _0x3345a2) {
  var _0x285b84 = crypto["enc"]["Utf8"]["parse"](_0x3345a2),
    _0x361e3d = crypto["AES"]
      ["encrypt"](_0x39d8b5, crypto["enc"]["Utf8"]["parse"](_0x478f45), {
        iv: _0x285b84,
        mode: crypto["mode"]["CBC"],
        padding: crypto["pad"]["Pkcs7"],
      })
      ["ciphertext"]["toString"](crypto["enc"]["Hex"]);
  return _0x361e3d;
}

function _0x44b32e(_0x478f45, _0x39d8b5, _0x3345a2) {
  for (
    var _0x285b84 = _0x39d8b5 - _0x478f45["length"],
      _0x3fba6b = "",
      _0x361e3d = 0;
    _0x361e3d < _0x285b84;
    _0x361e3d++
  )
    _0x3fba6b += _0x3345a2;
  return _0x3fba6b + _0x478f45;
}


var get_cookie = function (ts,seed,js_token,name) {
  var _0x478f45 = "lagou.com",
    _0x39d8b5 = ts,
    _0x3345a2 = "_" + _0x478f45 + "_" + _0x39d8b5,
    _0x285b84 = _0xb7b00b(
      "" + js_token["substr"](_0x3345a2["length"] - 32) + _0x3345a2,
      seed,
      ts + "00"
    );
    console.log("_0x285b84> ",_0x285b84)
    var _0x3fba6b = _0x285b84["split"]("-"),
    _0x361e3d = _0x3add6c(
    _0x44b32e(
      _0x3fba6b[1]["substr"](0, parseInt(_0x3fba6b[0], 10)) + "_" + _0x478f45,
      32,
      "0"
    ),
    _0x3fba6b[1]["substr"](parseInt(_0x3fba6b[0], 10)) +
      "-" +
      _0x3fba6b[2] +
      "_" +
      _0x478f45 +
      "_" +
      _0x39d8b5,
    _0x44b32e(_0x478f45, 16, "0")
  );
  return name + _0x361e3d;
};

exports.get_cookie = get_cookie
// var seed = '70231DFCD4FD5D6217E75FE9BA7DEF1CC435675D772F311687017D301A50DEBA336957687F1878F24B9C48ACA1D091CD',
//   ts= '16243424475408',
//   name= '2d4a619393bf',
//   js_token= '20210622000914-a16d61d6-6932-4a8d-92ab-2ddb6c00ef44';
// console.log(get_cookie(ts,seed,js_token,name));
